package com.info.zhiduoduo.common.excelconverter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.info.zhiduoduo.common.constants.invoice.InvoiceType;
import com.info.zhiduoduo.common.utils.StringUtil;

/**
 * 委托接单 收款账号类型 1:支付宝 2:银行卡
 * @author tianyonghong
 * @create 2022/8/4
 */
public class AccountPayTypeConverter implements Converter<Integer> {

    @Override
    public Class supportJavaTypeKey() {
        return null;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return null;
    }

    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty,
                                     com.alibaba.excel.metadata.GlobalConfiguration globalConfiguration) throws Exception {
        String value = cellData.getStringValue();
        if (StringUtil.equals(value, "支付宝")) return 1;
        if (StringUtil.equals(value, "银行卡")) return 2;
        return InvoiceType.GENERAL;
    }

    @Override
    public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty,
                                       com.alibaba.excel.metadata.GlobalConfiguration globalConfiguration) throws Exception {
        if (integer == 1) {
            return new CellData("支付宝");
        } else if (integer == 2) {
            return new CellData("银行卡");
        } else {
            return new CellData("");
        }
    }
}
